package com.test.daily.leetcode.y2022.m05.day0529.v01;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Set;

/**
 * @descriptions:
 * @author: Tom
 * @date: 2022/5/29 上午 11:52
 * @version: 1.0
 */
public class Code01_BFS {
    public static void bfs(Node start){
        if(start == null){
            return;
        }
        Queue<Node> queue = new LinkedList<>();
        Set<Node> set = new HashSet<>();
        queue.add(start);
        set.add(start);
        while(!queue.isEmpty()){
            Node cur = queue.poll();
            System.out.println(cur.value);
            for(Node next: cur.nexts){
                if(!set.contains(next)){
                    set.add(next);
                    queue.add(next);
                }
            }
        }
    }
}
